#define  _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
#include<algorithm>

using namespace std;

int minSumDistance(int* a, int num)
{
	int sum = 0;
	for (int i = 0; i < num; ++i)
	{
		for (int j = i; j < num; ++j)
		{
			sum += abs(a[i] - a[j]);
		}
	}
	return sum;
}

int main()
{
	int test = 0;
	cin >> test;
	while (test--)
	{
		int n = 0;
		cin >> n;
		int a[100000] = {0};
		for (int i = 0; i < n; ++i)
		{
			scanf("%d", &a[i]);
		}
		int sum = minSumDistance(a, n);
		cout << sum << endl;
	}
}